/**
 * Created by Administrator on 2017/6/7.
 */
angular.module('zhoudasheng', ['ui.router', 'zds.controller', 'zdsShop.controller', 'services', 'ngImgCrop'])
    .config(function($stateProvider, $urlRouterProvider, $httpProvider) {
        //$ionicConfigProvider.platform.ios.tabs.style('standard');
        //$ionicConfigProvider.platform.ios.tabs.position('bottom');
        //$ionicConfigProvider.platform.android.tabs.style('standard');
        //$ionicConfigProvider.platform.android.tabs.position('standard');
        //
        //$ionicConfigProvider.platform.ios.navBar.alignTitle('center');
        //$ionicConfigProvider.platform.android.navBar.alignTitle('left');
        //
        //$ionicConfigProvider.platform.ios.backButton.previousTitleText('').icon('ion-ios-arrow-thin-left');
        //$ionicConfigProvider.platform.android.backButton.previousTitleText('').icon('ion-android-arrow-back');
        //
        //$ionicConfigProvider.platform.ios.views.transition('ios');
        //$ionicConfigProvider.platform.android.views.transition('android');
        // Ionic uses AngularUI Router which uses the concept of states
        // Learn more here: https://github.com/angular-ui/ui-router
        // Set up the various states which the app can be in.
        // Each state's controller can be found in controllers.js
        $stateProvider.state('login', {
                url: '/login',
                templateUrl: 'tpl/login/login.html',
                controller: 'loginCtrl'
            }).state('login0', {
                url: '/login0',
                templateUrl: 'tpl/login/login0.html',
                controller: 'login0Ctrl'
            }).state('userLogin', {
                url: '/userLogin',
                templateUrl: 'tpl/login/userlogin.html',
                controller: 'userLoginCtrl'
            }).state('register', {
                url: '/register',
                templateUrl: 'tpl/login/register.html',
                controller: 'registerCtrl'
            }).state('forgetPwd', {
                url: '/forgetPwd',
                templateUrl: 'tpl/login/forgetpwd.html',
                controller: 'forgetPasswordCtrl'
            }).state('pinPaiQuan', {
                url: '/pinPaiQuan',
                templateUrl: 'tpl/shouye/pinpaiquan.html',
                controller: 'pinPaiQuanCtrl',
            }).state('message', {
                url: '/message',
                templateUrl: 'tpl/shouye/message.html',
                controller: 'messageCtrl'
            }).state('suoYouLiuYan', {
                url: '/suoYouLiuYan/:id',
                templateUrl: 'tpl/shouye/suoyouliuyan.html',
                controller: 'suoYouLiuYanCtrl'
            }).state('xiaoXiZhongXin', {
                url: '/xiaoXiZhongXin',
                templateUrl: 'tpl/shouye/xiaoxizhongxin.html',
                controller: 'xiaoXiZhongXinCtrl'
            }).state('zhuBaoDaPei', {
                url: '/zhuBaoDaPei/:id/:type',
                templateUrl: 'tpl/shouye/zhubaodapei.html',
                controller: 'zhuBaoDaPeiCtrl'
            }).state('zhuBaoXueTang', {
                url: '/zhuBaoXueTang/:id/:type',
                templateUrl: 'tpl/shouye/zhubaoxuetang.html',
                controller: 'zhuBaoXueTangCtrl'
            }).state('zhuBaoXueTangList', {
                url: '/zhuBaoXueTangList',
                templateUrl: 'tpl/shouye/zhubaoxuetanglist.html',
                controller: 'zhuBaoXueTangListCtrl'
            }).state('zhuBaoDaPeiList', {
                url: '/zhuBaoDaPeiList',
                templateUrl: 'tpl/shouye/zhubaodapeilist.html',
                controller: 'zhuBaoDaPeiListCtrl'
            }).state('sheJiShiMoKuai', {
                url: '/sheJiShiMoKuai',
                templateUrl: 'tpl/shouye/shejishimokuai.html',
                controller: 'sheJiShiMoKuaiCtrl'
            }).state('sheJiShiZhuanLan', {
                url: '/sheJiShiZhuanLan/:id',
                templateUrl: 'tpl/shouye/shejishizhuanlan.html',
                controller: 'sheJiShiZhuanLanCtrl'
            }).state('dingDanChuLi', {
                url: '/dingDanChuLi',
                templateUrl: 'tpl/personal/dingdanchuli.html',
                controller: 'dingDanChuLiCtrl'
            }).state('kaQuan', {
                url: '/kaQuan',
                templateUrl: 'tpl/personal/kaquan.html',
                controller: 'kaQuanCtrl'
            }).state('loveList', {
                url: '/loveList',
                templateUrl: 'tpl/personal/love_list.html',
                controller: 'loveListCtrl'
            }).state('mdzy', {
                url: '/mdzy',
                onExit: function() {
                    var map = api.require('bMap');
                    map.close();
                },
                templateUrl: 'tpl/personal/mdzy.html',
                controller: 'mdzyCtrl'
            }).state('mdzykd', {
                url: '/mdzykd',
                templateUrl: 'tpl/personal/mdzykd.html',
                controller: 'mdzykdtCtrl'
            }).state('mdzyOpenMap', {
                url: '/mdzyOpenMap',
                templateUrl: 'tpl/personal/mdzyopenmap.html',
                controller: 'mdzyOpenMapCtrl'
            }).state('dingDanXiangQing', {
                url: '/dingDanXiangQing/:id',
                templateUrl: 'tpl/personal/dingdanxiangqing.html',
                controller: 'dingDanXiangQingCtrl'
            }).state('tuiKuanShenQing', {
                url: '/tuiKuanShenQing/:id',
                templateUrl: 'tpl/personal/tuikuanshenqing.html',
                controller: 'tuiKuanShenQingCtrl'
            }).state('xiuGaiMiMa', {
                url: '/xiuGaiMiMa',
                templateUrl: 'tpl/personal/xiugaimima.html',
                controller: 'xiuGaiMiMaCtrl'
            }).state('xiuGaiGeRenNiCheng', {
                url: '/xiuGaiGeRenNiCheng',
                templateUrl: 'tpl/personal/xiugaigerennicheng.html',
                controller: 'xiuGaiGeRenNiChengCtrl'
            }).state('geRenZhongXin', {
                url: '/geRenZhongXin',
                templateUrl: 'tpl/personal/gerenzhongxin.html',
                controller: 'geRenZhongXinCtrl'
            }).state('woDeDingDan', {
                url: '/woDeDingDan',
                templateUrl: 'tpl/personal/wodedingdan.html',
                controller: 'woDeDingDanCtrl'
            }).state('woDeDingDanPingJia', {
                url: '/woDeDingDanPingJia',
                templateUrl: 'tpl/personal/wodedingdanpingjia.html',
                controller: 'woDeDingDanPingJiaCtrl'
            }).state('xiuGaiShouJiOld', {
                url: '/xiuGaiShouJiOld',
                templateUrl: 'tpl/personal/xiugaishoujiold.html',
                controller: 'xiuGaiShouJiOldCtrl'
            }).state('xiuGaiShouJiNew', {
                url: '/xiuGaiShouJiNew',
                templateUrl: 'tpl/personal/xiugaishoujinew.html',
                controller: 'xiuGaiShouJiNewCtrl'
            }).state('xiuGaiGeRenShuXing', {
                url: '/xiuGaiGeRenShuXing',
                templateUrl: 'tpl/personal/xiugaigerenshuxing.html',
                controller: 'xiuGaiGeRenShuXingCtrl'
            }).state('woDeDingDanTuiKuan', {
                url: '/woDeDingDanTuiKuan',
                templateUrl: 'tpl/personal/wodedingdantuikuan.html',
                controller: 'woDeDingDanTuiKuanCtrl'
            }).state('xiHuan', {
                url: '/xiHuan',
                templateUrl: 'tpl/personal/xihuan.html',
                controller: 'xiHuanCtrl'
            })
            .state('queRenDingDan', {
                url: '/queRenDingDan',
                templateUrl: 'tpl/shangcheng/querendingdang.html',
                controller: 'queRenDingDanCtrl'
            })
            .state('tuiKuanWeiDaoHuo', {
                url: '/tuiKuanWeiDaoHuo',
                templateUrl: 'tpl/personal/tuikuanweidaohuo.html',
                controller: 'tuiKuanWeiDaoHuoCtrl'
            })
            .state('tuiKuanYiDaoHuo', {
                url: '/tuiKuanYiDaoHuo',
                templateUrl: 'tpl/personal/tuikuanyidaohuo.html',
                controller: 'tuiKuanYiDaoHuoCtrl'
            })
            .state('shenQingTuiKuanList', {
                url: '/shenQingTuiKuanList',
                templateUrl: 'tpl/personal/shenqingtuikuanlist.html',
                controller: 'shenQingTuiKuanListCtrl'
            })
            .state('huoDongTuiJianYe', {
                url: '/huoDongTuiJianYe/:id',
                templateUrl: 'tpl/shouye/huodongtuijianye.html',
                controller: 'huoDongTuiJianYeCtrl'
            })
            .state('paymentCenter',{
                url:'/paymentCenter/:id/:type',
                templateUrl:'tpl/personal/paymentCenter.html',
                controller:'paymentCenterCtrl'
            })

            //商城
            .state('zhuanTiChanPin', {
                url: '/zhuanTiChanPin/:id',
                templateUrl: 'tpl/shangcheng/zhuantichanpin.html',
                controller: 'zhuanTiChanPinCtrl'
            })
            .state('queRenDingDan2', {
                url: '/queRenDingDan2',
                templateUrl: 'tpl/shangcheng/querendingdang2.html',
                controller: 'queRenDingDan2Ctrl'
            }).state('search22', {
                url: '/search22',
                templateUrl: 'tpl/shangcheng/search2-2.html',
                controller: 'search22Ctrl'
            }).state('search23', {
                url: '/search23',
                templateUrl: 'tpl/shangcheng/search2-3.html',
                controller: 'search23Ctrl'
            }).state('shangCheng', {
                url: '/shangCheng',
                onExit: function() {
                    window.onscroll = null;
                },
                templateUrl: 'tpl/shangcheng/shangcheng.html',
                controller: 'shangChengCtrl'
            }).state('souSuoJieGuo', {
                url: '/souSuoJieGuo',
                onExit: function() {
                    window.onscroll = null;
                },
                templateUrl: 'tpl/shangcheng/sousuojieguo.html',
                controller: 'souSuoJieGuoCtrl',
            }).state('hotRecommend', {
                url: '/hotRecommend',
                onExit: function() {
                    window.onscroll = null;
                },
                templateUrl: 'tpl/shangcheng/hotRecommend.html',
                controller: 'hotRecommendCtrl'
            }).state('tianJiaXinDiZhi', {
                url: '/tianJiaXinDiZhi/:id',
                templateUrl: 'tpl/shangcheng/tianjiaxindizhi.html',
                controller: 'tianJiaXinDiZhiCtrl'
            }).state('tianJiaXinDiZhi2', {
                url: '/tianJiaXinDiZhi2',
                templateUrl: 'tpl/shangcheng/tianjiaxindizhi2.html',
                controller: 'tianJiaXinDiZhi2Ctrl'
            }).state('chanPinXiangQing', {
                url: '/chanPinXiangQing/:id',
                onExit: function() {
                    window.onscroll = null;
                },
                templateUrl: 'tpl/shangcheng/changpingxiangqing.html',
                controller: 'chanPinXiangQingCtrl'
            }).state('baoBeiPingLun', {
                url: '/baoBeiPingLun/:id',
                onExit: function() {
                window.onscroll = null;
                },
                templateUrl: 'tpl/shangcheng/baobeipinglun.html',
                controller: 'baoBeiPingLunCtrl'
            }).state('gouWuChe', {
                // url:'/chanPinXiangQing/:id',
                url: '/gouWuChe',
                reload: true,
                templateUrl: 'tpl/buyCart/gouwuche.html',
                controller: 'gouWuCheCtrl'
            }).state('shenQingDaoKuanYiDaoHuo', {
                url: '/shenQingDaoKuanYiDaoHuo',
                templateUrl: 'tpl/buyCart/shenqingdaokuanyidaohuo.html',
                controller: 'shenQingDaoKuanYiDaoHuoCtrl'
            }).state('wuLiuXinXi', {
                url: '/wuLiuXinXi',
                reload: true,
                templateUrl: 'tpl/personal/wuliuxinxi.html',
                controller: 'wuLiuXinXiCtrl'
            }).state('shouHouFuWu', {
                url: '/shouHouFuWu',
                templateUrl: 'tpl/personal/shouhoufuwu.html',
                controller: 'shouHouFuWuCtrl'
            }).state('daoHanFenLei', {
                url: '/daoHanFenLei',
                templateUrl: 'tpl/shangcheng/daohanfeilei.html',
                controller: 'daoHanFenLeiCtrl'
            }).state('shangChengErJi', {
                url: '/shangChengErJi',
                templateUrl: 'tpl/shangcheng/shangchengerjiye1.html',
                controller: 'shangChengErJiCtrl'
            }).state('shaoMaoJieGuoErr', {
                url: '/shaoMaoJieGuoErr',
                templateUrl: 'tpl/shangcheng/shaomaojieguo_err.html',
                controller: 'shaoMaoJieGuoErrCtrl'
            }).state('shaoMaoJieGuoSuc', {
                url: '/shaoMaoJieGuoSuc',
                templateUrl: 'tpl/shangcheng/shaomaojieguo_suc.html',
                controller: 'shaoMaoJieGuoSucCtrl'
            })
            .state('gouMaiWanCheng', {
                url: '/gouMaiWanCheng',
                templateUrl: 'tpl/shangcheng/goumaiwancheng.html',
                controller: 'gouMaiWanChengCtrl'
            })
            .state('huoDongTuiJian', {
                url: '/huoDongTuiJian',
                templateUrl: 'tpl/shouye/huodongtuijian.html',
                controller: 'huoDongTuiJianCtrl'
            })
            .state('shangPinpPingJia', {
                url: '/shangPinpPingJia',
                templateUrl: 'tpl/personal/shuangpinpingjia.html',
                controller: 'shangPinPingJiaCtrl'
            })
            .state('shouHouZhuangTaiList', {
                url: '/shouHouZhuangTaiList',
                templateUrl: 'tpl/personal/shouhouzhuangtailist.html',
                controller: 'shouHouZhuangTaiListCtrl'
            })
            .state('shouHouZhuangTai', {
                url: '/shouHouZhuangTai',
                templateUrl: 'tpl/personal/shouhouzhuangtai.html',
                controller: 'shouHouZhuangTaiCtrl'
            })
            .state('zhiFuZhongJianYe', {
                url: '/zhiFuZhongJianYe/:id/:oid',
                templateUrl: 'tpl/shangcheng/zhifuzhongjianye.html',
                controller: 'zhiFuZhongJianYeCtrl'
            })
            .state('loading',{
                url: '/loading',
                templateUrl: 'loading.html',
                controller: 'loadingCtrl',
            })
            .state('guide',{
                url: '/guide',
                templateUrl: 'guide.html',
                controller: 'guideCtrl',
            })
            .state('mytest',{
                url: '/mytest',
                templateUrl: 'mytest.html',
                controller: 'mytestCtrl',
            });
        // setup an abstract state for the tabs directive

        $urlRouterProvider.otherwise(function($injector, $location){
            var $state = $injector.get('$state');
            $state.go('loading');
        });
    })
    .run(function($rootScope, $state, $stateParams, $location, $http) {
        var isfinisha = false;
        //setTimeout(function() {
        apiready = function() {
            api.addEventListener({
                name: 'keyback'
            }, function(ret, err) {
                var href = location.href.split("#")[1];
                if (href == "/pinPaiQuan" || href == "/shangCheng" || href == "/geRenZhongXin") {
                    if (isfinisha) {
                        api.closeWidget({
                            silent: true
                        });
                    } else {
                        api.toast({
                            msg: '再按一次返回键退出',
                            duration: 2000,
                            location: 'bottom'
                        });
                        isfinisha = true;
                        bolsettime();
                    }
                } else {
                    history.back();
                }
            });



        };
        //}, 1000);

        function bolsettime() {
            setTimeout(function() {
                isfinisha = false;
            }, 1000);
        }

        $rootScope.backButton = function() {
            history.back();
        };

        //登录后返回记住的页面
        $rootScope.notLoginMark = function(){
            localStorage.setItem('loginUrl',angular.toJson({
                url: $location.$$path,
                tail: $location.search()
            }));
            $state.go("login0");
        };
        $rootScope.goLoginURL = function(){
            var loginUrl = angular.fromJson(localStorage.getItem('loginUrl')).url;
            if (loginUrl) {
                var tail = angular.fromJson(localStorage.getItem('loginUrl')).tail;
                if (tail) {
                    $location.path(loginUrl).search(tail);
                    $location.replace();
                } else {
                    $location.path(loginUrl);
                    $location.replace();
                }
                localStorage.removeItem("loginUrl");
            } else {
                $state.go('pinPaiQuan');
            }
        };
    });

//产品详情头部滚动条
// $(window).scroll(function() {
//     var winPos = $(window).scrollTop() * 0.0066;
//     if (winPos < 1.5) {
//         $("#cpxq_rgba").css("background-color", "rgba" + "(" + 255 + "," + 255 + "," + 255 + "," + winPos + ")");
//         $("#cpxq_rgba span").css("color", "rgba" + "(" + 50 + "," + 50 + "," + 50 + "," + winPos + ")");
//     }
// });
